﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace KhtApi.Model
{
    public class Bom
    {
        /// <summary>
        /// InstanceId
        /// </summary>
        public string Id { get; set; }
        /// <summary>
        /// BOM单号
        /// </summary>
        public string BomId { get; set; }
        public string ItemCode { get; set; }
        public string Name { get; set; }
        public string ModelNo { get; set; }
        public string Spec { get; set; }
        //[JsonProperty(NullValueHandling = NullValueHandling.Include)]
        public double? Cost { get; set; }
        public EOrigin Origin { get; set; }
        /// <summary>
        /// 自产|外购|客供|委外
        /// </summary>
        public string OriginCn
        {
            get
            {
                return Origin.ToString();
            }
            set
            {
                if (Enum.TryParse(value, out EOrigin origin))
                {
                    Origin = origin;
                }
                else
                {
                    throw (new Exception("不支持的产品来源类型！请确保输入的字符串为‘自产|外购|客供|委外’四种之一"));
                }
            }
        }
        public string Catagory1 { get; set; }
        public string Catagory2 { get; set; }
        public string Catagory3 { get; set; }
        public string Version { get; set; }
        /// <summary>
        /// 审核状态：已审、未审
        /// </summary>
        public ECheckStatus CheckStatus { get; set; }
        public string CheckStatusCn
        {
            get
            {
                return CheckStatus.ToString();
            }
            set
            {
                if (Enum.TryParse(value, out ECheckStatus status))
                {
                    CheckStatus = status;
                }
                else
                {
                    throw (new Exception("无法将输入的字符串转换成ECheckStatus，请确保输入的字符串为'已审、未审'"));
                }
            }
        }
        /// <summary>
        /// 生效状态：生效、未生效
        /// </summary>
        public EAffectStatus AffectStatus { get; set; }
        public string AffectStatusCn
        {
            get
            {
                return AffectStatus.ToString();
            }
            set
            {
                if (Enum.TryParse(value, out EAffectStatus status))
                {
                    AffectStatus = status;
                }
                else
                {
                    throw (new Exception("无法将输入的字符串转换成EAffectStatus，请确保输入的字符串为'生效、未生效'"));
                }
            }
        }
        public List<BomMeterial> Materials { get; set; }

    }

    public class BomMeterial
    {
        public string ItemCode { get; set; }
        public string Name { get; set; }
        public string ModelNo { get; set; }
        public string Spec { get; set; }
        public double? Cost { get; set; }
        public EOrigin Origin { get; set; }
        /// <summary>
        /// 自产|外购|客供|委外
        /// </summary>
        public string OriginCn
        {
            get
            {
                return Origin.ToString();
            }
            set
            {
                if (Enum.TryParse(value, out EOrigin origin))
                {
                    Origin = origin;
                }
                else
                {
                    throw (new Exception("不支持的产品来源类型！请确保输入的字符串为‘自产|外购|客供|委外’四种之一"));
                }
            }
        }
        public string Catagory1 { get; set; }
        public string Catagory2 { get; set; }
        public string Catagory3 { get; set; }
        public string Unit { get; set; }
        public double Qty { get; set; }
        public string Note { get; set; }
    }
}
